// created by noellynch
// Mar 17, 2011

package com.apachepivot.utils;

import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.wtk.BoxPane;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.Window;

public class ApachePivotUtils {
	static	public	Component		findByName(Container cl_par, String str_name) {
		for(Component lcl_comp : cl_par) {
			if(lcl_comp.getName() != null) {
				if(lcl_comp.getName().equals(str_name)) {
					return lcl_comp;
				}
			}
			
			if(lcl_comp instanceof Container) {
				Component		lcl_compF = findByName((Container)lcl_comp, str_name);
				if(lcl_compF != null) {
					return lcl_compF;
				}
			}
		}
		
		return null;
	}
	
	static	public	Window		getWindowParent(Component cl_comp) {
		Container		lcl_par = cl_comp.getParent();
		
		while(!(lcl_par instanceof Window)) {
			lcl_par = lcl_par.getParent();
		}
		
		return (Window)lcl_par;
	}
	
	static	public	ArrayList		fromJavaToPivotArray(java.util.ArrayList<?> cla_array) {
		ArrayList		lcl_temp = new ArrayList();
		
		for(Object lcl_obj : cla_array) {
			lcl_temp.add(lcl_obj);
		}
		
		return lcl_temp;
	}
	
	static	public	ArrayList		fromJavaToPivotArray(java.util.Collection<?> cla_array) {
		ArrayList		lcl_temp = new ArrayList();
		
		for(Object lcl_obj : cla_array) {
			lcl_temp.add(lcl_obj);
		}
		
		return lcl_temp;
	}
	
	static	public	void	setStyle(Component cl_comp, String str_styleName, Object cl_styleObject) {
		cl_comp.getStyles().put(str_styleName, cl_styleObject);
	}
	
	static	public	void	fillBoxPane(BoxPane cl_box) {
		setStyle(cl_box, "fill", true);
	}
}
